package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class PWDDemo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username = scanner.nextLine();
        System.out.println("请修改密码");
        String password = scanner.nextLine();
        System.out.println("请修改昵称");
        String nickname = scanner.nextLine();
        System.out.println("请修改年龄");
        int age = Integer.parseInt(scanner.nextLine());
        try (Connection connection = DBUtil.getConnection()) {
            Statement statement = connection.createStatement();
            String sql="UPDATE user\n" +
                    "SET password='"+password+"',nickname='"+nickname+"',age="+age+"\n " +
                    "WHERE username='"+username+"'";
            int num=statement.executeUpdate(sql);
            System.out.println("修改成功");
        }catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
